package com.zhangyu.shadow.ec.main.personal.order;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.tepth.shadow.ui.recycler.DataConverter;
import com.tepth.shadow.ui.recycler.MultipleField;
import com.tepth.shadow.ui.recycler.MultipleItemEntity;

import java.util.ArrayList;

/**
 * @author zhangyu
 * @date 2018/1/4
 */

public class OrderDataConverter extends DataConverter {
    @Override
    public ArrayList<MultipleItemEntity> convert() {
        final JSONArray jsonArray = JSONObject.parseObject(getJsonData()).getJSONArray("data");
        final int size = jsonArray.size();
        for (int i = 0; i < size; i++) {
            final JSONObject jsonObject = jsonArray.getJSONObject(i);
            final String thumb = jsonObject.getString("thumb");
            final String title = jsonObject.getString("title");
            final int id = jsonObject.getInteger("id");
            final String time = jsonObject.getString("time");
            final double price = jsonObject.getDouble("price");

            final MultipleItemEntity multiItemEntity = MultipleItemEntity.builder()
                    .setItemType(OrderListItemType.ITEM_ORDER_LIST)
                    .setField(MultipleField.IMAGE_URL, thumb)
                    .setField(MultipleField.TITLE, title)
                    .setField(MultipleField.ID, id)
                    .setField(OrderItemFields.TIME,time)
                    .setField(OrderItemFields.PRICE, price)
                    .build();
            mEntities.add(multiItemEntity);
        }
        return mEntities;
    }
}
